package org.lex.utils.text;

public enum SizeUnit {
	One(0, ""), K(1, "Kilo"), M(2, "Mega"), G(3, "Giga"), T(4, "Tera"), P(5, "Peta"), E(6, "Exa");
	// ��������λ̫���Ѿ�������long����ʾ,Ϊ�˼������������
	// Z( 0, "Zetta"),
	// Y( 0, "Yotta");
	// ================== constants field ===============
	static final int DefaultLength1 = 4;
	static final int DefaultLength2 = 3;
	// ===============================================
	int bits = 0;
	long value = 0L;
	String lowcaseShort = "";
	String lowcaseFull = "";
	String upcaseShort = "";
	String upcaseFull = "";

	private SizeUnit(int bits, String upcaseFull) {
		this.bits = bits;
		this.value = (long) Math.pow(2, 10 * bits);
		if (upcaseFull.length() > 0) {
			this.upcaseFull = upcaseFull;
			this.upcaseShort = upcaseFull.substring(0, 1);
			this.lowcaseFull = upcaseFull.toLowerCase();
			this.lowcaseShort = lowcaseFull.substring(0, 1);
		}
	}

	public static long convert(long size, SizeUnit unit) {
		return size * unit.value;
	}

	public static double convert(double size, SizeUnit unit) {
		return size * unit.value;
	}

	public int getBits() {
		return this.bits;
	}

	public long getValue() {
		return this.value;
	}

	public String getStyle(SizeFormat.Style unit) {
		switch (unit) {
		case LOWCASE_SHORT:
			return this.lowcaseShort;
		case LOWCASE_FULL:
			return this.lowcaseFull;
		case UPCASE_SHORT:
			return this.upcaseShort;
		case UPCASE_FULL:
			return this.upcaseFull;
		default:
			return "";
		}
	}
}
